<%@page import="durak.server.control.GamesManager"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@page import="durak.utils.*, durak.server.control.*, java.util.Set, durak.utils.Constants"%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Durak Games</title>
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen"/>
<link rel="stylesheet" href="css/UI.css" type="text/css" media="screen"/>
<script src="js/jquery-1.8.2.js"></script>
<script src="js/jquery-ui-1.9.0.custom.js"></script>
<script src="js/jquery.redirect.min.js"></script>
<script src="js/jquery.form.js"></script>
<script src="js/utils.js"></script>
</head>

<body>
<% String usernameFromSession = SessionUtils.getUsername(request);
		 	if (usernameFromSession == null) {
				usernameFromSession = new String("");
		 	} 
%>
<input type="hidden" id=user_name value="<%=usernameFromSession%>"/>

<div id="CreateNewGame">
		<div><input class="newGameButton" class="ui-button-text" type="button" value="New Game" onclick="openNeGameDialog()"/></div>
		<div><input class="newGameButtonFromXML" class="ui-button-text" type="button" value="Load Game from XML" onclick="openGameFromXMLDialog()"/></div>
		<div id="newGameMenu" class="ui-dialog-content ui-widget-content" style="width: auto; min-height: 0px; height: 210px;">
		<form>
			Game Name: <input type="text" id="newGameName" class="text ui-widget-content ui-corner-all"/><br/>
			Number of Human players: <select id="newGameHumanPlayers"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select><br/>
			Number of Auto players: <select id="newGameAutoPlayers"><option value="0">0</option><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option></select><br/>
			<input type="button" value="Submit" onclick="newGameSubmit()"/><input type="button" value="Cancel" onclick="closeMenu()">
		</form>
	</div>
	<div id="gameFromXMLMenu" class="ui-dialog-content ui-widget-content" style="width: 300; min-height: 0px; height: 210px;">
		<form id="upload-form" class="upload-box" action="upload" method="post" enctype="multipart/form-data">
    		<h1>Upload New Game</h1>
    		<input type="file" id="file" name="file1" />
    		<div id="upload-error" class="error">${uploadError}</div>
    		<input type="submit" id="upload-button" value="upload" onclick="closeXMLuploadDialog" />
		</form>
	</div>
	
	</div>

<ol id=selectGames>
<% GamesManager gamesManager = ServletUtils.getGamesManager(getServletContext());
	Set<Game> activeGames = gamesManager.getActiveGames();
	for (Game game : activeGames) {
		out.print("<li class=\"ui-widget-content\">" + game.getName() + "</li>");
		
	}
%>
</ol>
<input type="button" class="ui-button-text joinSelectedGame" id="join_selected_game" value="Join Selected Game">

</body>
</html>